package cn.bcsp.service;

import cn.bcsp.mapper.SysUserMapper;
import cn.bcsp.pojo.SysUser;
import cn.bcsp.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: TODO
 * @author: wangyue
 * @date: 2021年07月14日 14:33
 */
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {

    @Resource(name = "sysUserMapper")
    private SysUserMapper sysUserMapper;


    @Override
    public SysUser querySysUser(int id) {
        return sysUserMapper.selectById(id);
    }

    @Override
    public int addSysUser(SysUser sysUser) {
        return sysUserMapper.insertSysUser(sysUser);
    }

    @Override
    public PageUtil<SysUser> querySysUserByPage(String realName, int roleId, int currentPage) {

        PageUtil<SysUser> pageUtil = new PageUtil<>();
        //总记录数
        int totalCount = sysUserMapper.count(realName, roleId);
        //每页显示的条数
        int pageSize = 5;
        pageUtil.setTotalCount(totalCount);
        pageUtil.setPageSize(pageSize);
        //当前页
        pageUtil.setCurrentPage(currentPage);
        //获得每页开始条数
        int startRow = pageUtil.getStartRow();
        //当前页的数据
        List<SysUser> list = sysUserMapper.selectSysUsers(realName, roleId, startRow, pageSize);
        //在pageUtil中封装当前页的数据
        pageUtil.setLists(list);

        return pageUtil;
    }

    @Override
    public SysUser login(String account, String password) {
        return sysUserMapper.selectSysUser(account, password);
    }

    @Override
    public int editSysUser(SysUser sysUser) {
        return sysUserMapper.updateSysUser(sysUser);
    }

    @Override
    public int delById(Integer id) {
        return sysUserMapper.deleteById(id);
    }


    @Override
    public int findAccount(String account) {
        return sysUserMapper.selectOOne(account);
    }
}




